// pages/coupon/coupon.js
var app = getApp();
var utils = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ischecked: false,
    butvalue: -1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    var goodsList = app.globalData.goodsList;
    that.mycouponTap(goodsList);
    console.log(that.data.butvalue);
  },
  // 获取我的优惠券可使用数据 
  mycouponTap: function(goodslist) {
    var that = this;
    utils.http("/api/v1/order/my_coupon", {
      goods_list: goodslist
    }, function(res) {
      for (var i in res.datas.data_list) {
        if (app.globalData.couponId == res.datas.data_list[i].id) {
          that.setData({
            butvalue: i,
          })
        }

      }
      that.setData({
        couponList: res.datas.data_list
      })
    })
  },
  //优惠券返回订单
  radioChange(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    that.setData({
      butvalue: index
    })
    app.globalData.couponMoney = that.data.couponList[index].money;
    app.globalData.couponId = that.data.couponList[index].id;
    wx.navigateBack({})
  },
  radioChange11: function(e) {
    var that = this;
    that.setData({
      butvalue: -1
    })

    app.globalData.couponMoney = undefined;
    app.globalData.couponId = undefined;
    wx.navigateBack({})
  }
})